package com.cheejee.goodscenter.service.impl;

import java.time.Instant;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cheejee.goodscenter.dao.SaleCountMapper;
import com.cheejee.goodscenter.module.entity.SaleCount;
import com.cheejee.goodscenter.service.SaleCountService;
import com.cheejee.goodscenter.validated.Check;
import com.cheejee.goodscenter.validated.InsertGroup;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * @author CARRY
 * @Date 2020年10月27日上午1:58:55
 */
@Service
public class SaleCountServiceImpl implements SaleCountService{

	@Resource
	private SaleCountMapper sm;
	

	@Override
	public SaleCount querySaleById(Long id) {
		
		return sm.selectByPrimaryKey(id);
	}
	
	@Override
	public Page<SaleCount> querySaleCount(Long goodsId, Long skuId, int pageNum, int pageSize) {
		
		return PageHelper.startPage(pageNum, pageSize).doSelectPage(() -> sm.selectBySelective(goodsId, skuId));
	}

	@Override
	public Page<SaleCount> querySaleCountBetween(Date begin, Date end, Long goodsId, Long skuId, int pageNum, int pageSize) {
		
		return PageHelper.startPage(pageNum, pageSize).doSelectPage(() -> sm.selectBetween(goodsId, skuId, begin, end));
	}

	@Override
	@Check(message = "新增销售流水不能为空", group = InsertGroup.class)
	public int addSaleCount(SaleCount salecount) {
		salecount.setTime(Date.from(Instant.now()));
		
		return sm.insertSelective(salecount);
	}

	@Override
	public int deleteSaleCount(Long... id) {
		
		return sm.deleteById(id);
	}


}
